
package vv.lines.view;

import vv.lines.core.IActionHandler;
import vv.lines.core.animations.Animation;
import vv.lines.core.animations.AnimationType;

/**
 *
 * @author vpotapenko
 */
public abstract class ViewFactory {

    public ViewTimer createViewTimer(ViewTimerListener listener) {
        ViewTimer timer = newViewTimer();
        timer.setListener(listener);
        return timer;
    }

    public WindowView createWindowView(IActionHandler handler) {
        return newWindowView(handler);
    }

    protected abstract WindowView newWindowView(IActionHandler handler);

    protected abstract FieldView newFieldView();

    public FieldView createFieldView(IActionHandler actionHandler) {
        return viewWithHandler(newFieldView(), actionHandler);
    }

    protected abstract CellView newCellView();

    protected abstract BallView newBallView();

    protected abstract ViewTimer newViewTimer();

    protected abstract Animation newMoveAnimation();

    protected abstract Animation newActiveAnimation();

    protected abstract Animation newShowAnimation();

    protected abstract Animation newHideAnimation();

    private <T extends ActiveView> T viewWithHandler(T view, IActionHandler actionHandler) {
        if (view != null) view.setHandler(actionHandler);

        return view;
    }

    public CellView createCellView(IActionHandler actionHandler) {
        return viewWithHandler(newCellView(), actionHandler);
    }

    public BallView createBallView(IActionHandler actionHandler) {
        return viewWithHandler(newBallView(), actionHandler);
    }

    public Animation createAnimation(AnimationType type) {
        switch (type) {
            case ACTIVE: return newActiveAnimation();
            case HIDE: return newHideAnimation();
            case MOVE: return newMoveAnimation();
            case SHOW: return newShowAnimation();
            default: return null;
        }
    }

    public abstract void showMessageBox(String title, String text);

    public abstract String showInputBox(String message, String initialValue);

    public TextDialogView createTextWindowView() {
        return newTextWindowView();
    }

    protected abstract TextDialogView newTextWindowView();
}
